package com.cmii.sjw.department.control.jsc.util;

import lombok.Data;

import java.io.Serializable;

/**
 * @author jorlin
 * @date 2024-02-12 15:48
 */
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 响应码
     */
    private int code;

    /**
     * 信息
     */
    private String message;

    /**
     * 响应体
     */
    private T data;

    public Result() {

    }

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功
     *
     * @return result
     */
    public static <T> Result<T> success() {
        return new Result(200, "操作成功", null);
    }

    /**
     * 成功
     *
     * @return result
     */
    public static <T> Result<T> success(T data) {
        return new Result(200, "操作成功", data);
    }

    /**
     * 成功
     *
     * @return result
     */
    public static <T> Result<T> success(String message, T data) {
        return new Result(200, message, data);
    }

    /**
     * 失败
     *
     * @return result
     */
    public static <T> Result<T> error(String message, T data) {
        return new Result(400, message, data);
    }

    /**
     * 失败
     *
     * @return result
     */
    public static <T> Result<T> error(String message) {
        return new Result(400, message, null);
    }

    public static <T> Result<T> error(int code, String message) {
        return new Result(code, message, null);
    }
}
